package com.nuanshui.heatedloan.controller.display.accountbill;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.nuanshui.framework.utils.LogUtil;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.controller.BaseController;
import com.nuanshui.heatedloan.fund.facade.UserAccountBillService;
import com.nuanshui.heatedloan.fund.facade.UserBindAccountService;
import com.nuanshui.heatedloan.fund.integration.accountbill.AccountBillFacade;
import com.nuanshui.heatedloan.fund.model.UserAccountBill;
import com.nuanshui.heatedloan.userinfo.facade.UserService;

/**
 * 用户资金明细Controller
 * @author Junyan2015
 * @date 2016年2月16日 下午1:51:43
 */
@RestController
@RequestMapping("/user/accountBill/")
public class UserAccountBillController extends BaseController {

	@Reference(url=GlobalParam.FUND_DUBBO_SERVER,timeout=GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.FUND_DUBBO_SERVER_VERSION)
	private UserAccountBillService userAccountBillService;
	@Reference(url=GlobalParam.FUND_DUBBO_SERVER,timeout=GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.FUND_DUBBO_SERVER_VERSION)
	private UserBindAccountService userBindAccountService;
	@Reference(url=GlobalParam.USER_DUBBO_SERVER,timeout=GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.USER_DUBBO_SERVER_VERSION)
	private UserService userService;
	
	@Autowired
	private AccountBillFacade accountBillFacade;
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	/**
	 * 根据num获得相应的账单信息
	 * @author Junyan2015
	 * @date 2016年2月16日 下午1:52:32
	 * @param num 第几个点击块
	 * @param pager
	 * @return
	 */
	@RequestMapping(value = "listUserAccountBill",method = RequestMethod.POST)
	public String listUserAccountBill(Integer num, Pageable pager) {
		LogUtil.info(logger, "根据num:"+num+"获得相对应的 账单信息");
		String userId = getCurrentUser().getId();
		//Integer isAdmin =  userService.isAdministrator(userId);
		Integer isAdmin  = 0;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("isAdmin", isAdmin);
		List<UserAccountBill> list = userAccountBillService.findUserAccountBill(num, userId, pager);
		map.put("list", list);
		return success(map);
	}
	
	/**
	 * 根据账单id获得账单详情
	 * @author Junyan2015
	 * @date 2016年2月16日 下午1:53:09
	 * @param billId
	 * @return
	 */
	@RequestMapping(value = "billDetail",method = RequestMethod.POST)
	public String getBillDetail(String billId) {
		LogUtil.info(logger, "根据账单id"+billId+"获得账单详情");        
        Map<String, Object> map = accountBillFacade.getAccountDetail(billId);
        return success(map);
	} 
}
